from django.db import models

from user.models import UserModel
from utils.basemodel import BaseModel


# Create your models here.


class CouponModel(models.Model):
    name = models.CharField(max_length=50,verbose_name='优惠卷名称')
    price = models.DecimalField(decimal_places=2,max_digits=10,verbose_name='优惠价格')
    condition = models.CharField(max_length=100,verbose_name='条件')
    start_time = models.DateTimeField(verbose_name='开始时间')
    end_time = models.DateTimeField(verbose_name='结束时间')
    is_show = models.BooleanField(verbose_name='是否有效')
    number = models.IntegerField(verbose_name='数量',default=1000)
    type = models.CharField(max_length=50,verbose_name='类型')

    class Meta:
        db_table = 'fgcoupon'

    def __str__(self):
        return self.name

class UserCouponModel(BaseModel):
    user = models.ForeignKey(UserModel,on_delete=models.CASCADE,verbose_name='用户信息')
    coupon = models.ForeignKey(CouponModel,on_delete=models.CASCADE,verbose_name='优惠卷信息')

    class Meta:
        db_table = 'fgusercoupon'


